import { http } from '@/utils/request'
import type { DictTypeItem, DictTypeParams, QueryParams } from './type'

const prefix = import.meta.env.VITE_API_SYS

// 查询字典类型列表
export function listType(params: QueryParams & Page) {
	return http.get<ResPage<DictTypeItem[]>>(`${prefix}/dict/type/list`, params)
}

// 查询字典类型详细
export function getType(dictId: string) {
	return http.get<DictTypeItem>(`${prefix}/dict/type/${dictId}`)
}

// 新增字典类型
export function addType(data: DictTypeParams) {
	return http.post(`${prefix}/dict/type`, data)
}

// 修改字典类型
export function updateType(data: DictTypeParams) {
	return http.put(`${prefix}/dict/type`, data)
}

// 删除字典类型
export function delType(dictId: string) {
	return http.delete(`${prefix}/dict/type/${dictId}`)
}

// 刷新字典缓存
export function refreshCache() {
	return http.delete(`${prefix}/dict/type/refreshCache`)
}

// 获取字典选择框列表
export function optionselect() {
	return http.get<{ dictName: string; dictType: string }[]>(`${prefix}/dict/type/optionselect`)
}
// 导出
export function typeExport(data: QueryParams & Page) {
	return http.postFile<ExportResponse>(`${prefix}/dict/type/export`, data, {
		responseType: 'blob',
		headers: {
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	})
}
